import numpy as np
import pandas as pd
from pandas import Series, DataFrame

df_01 = DataFrame(np.random.randint(0, 10, (4, 4)), index=[1, 2, 3, 4],
                  columns=["a", "b", "c", "d"])
df_02 = DataFrame(np.random.randint(0, 10, (4, 4)))
print(df_01)
print(df_02)
dict_01 = {
    'Province': ['Guangdong', 'Beijing', 'Qinghai', 'Fujian'],
    'pop': [1.3, 2.5, 1.1, 0.7],
    'year': [2018, 2018, 2018, 2018]}
df_03 = pd.DataFrame(dict_01, index=[1, 2, 3, 4])
print(df_03)
dict_02 = {"a": [1, 2, 3], "b": [4, 5, 6]}
df_04 = pd.DataFrame.from_dict(dict_02)
print(df_04)
# 索引相同的情况下，相同索引的值会相对应，缺少的值会添加NaN
dict_03 = {
    'Name': pd.Series(['zs', 'ls', 'we'], index=['a', 'b', 'c']),
    'Age': pd.Series(['10', '20', '30', '40'], index=['a', 'b', 'c', 'd']),
    'country': pd.Series(['中国', '日本', '韩国'], index=['a', 'c', 'b'])
}
df_05 = pd.DataFrame(dict_03)
print(df_05)
# Get values in an dataframe
print(df_05.values)
print(df_05.info())
print(df_05.head(2))
print(df_05[["Name", "Age"]])
print(df_05.loc["a", "Name"])
print(df_05.loc["a", ["Name", "Age"]])
df_06 = df_05.sort_values(by="Age", ascending=False)
print(df_06)
df_07 = pd.DataFrame(np.arange(9).reshape(3, 3), index=['bj', 'sh', 'gz'], columns=['a', 'b', 'c'])
print(df_07)
df_07.index = ["Beijing", "Shanghai", "Guangzhou"]
print(df_07)
df_07.rename(index={"Beijing": "beijing"}, columns={"a": "A"}, inplace=True)


def change_index(x):
    return x + "_ABC"


df_07.rename(index=change_index, columns=change_index, inplace=True)
print(df_07)
df_08 = pd.DataFrame({"X": range(5), "Y": range(5), "S": list("abcde"), "Z": [6, 7, 8, 9, 10]})
df_09 = df_08.set_index("S", drop=False)
df_09.index.name = None
print(df_09)
df_10 = pd.DataFrame([['Snow', 'M', 22], ['Tyrion', 'M', 32], ['Sansa', 'F', 18],
                      ['Arya', 'F', 14]], columns=['name', 'gender', 'age'])
df_10["score"] = [80, 85, 90, 95]
print(df_10)
